{% extends 'base.html' %}
{% load static %}
{% block title %}
    DjangoBlog首页 - 发现精彩内容
{% endblock %}
{% block head %}
    {{ block.super }}
    <link rel="stylesheet" href="{% static 'css/base.css' %}?v=1.0">
{% endblock %}
{% block main %}
    <div class="mb-6 text-center">
        <h1 class="display-4 text-transparent bg-clip-text bg-gradient-to-r from-purple-600 to-pink-500">
            Django博客
        </h1>
        <p class="text-muted mt-2">发现精彩内容，分享你的想法</p>
    </div>

    <!-- 博客过滤器 -->
    <div class="bg-light p-4 rounded-lg shadow-sm mb-6">
        <div class="d-flex flex-wrap gap-3 justify-content-between items-center">
            <div class="text-muted">共 {{ blogs|length }} 篇博客</div>
            <div>
                <form method="get" action="">
                    <select name="sort_by" class="form-control form-control-sm w-auto d-inline-block" onchange="this.form.submit()">
                        <option value="newest" {% if sort_by == 'newest' %}selected{% endif %}>最新发布</option>
                        <option value="most_likes" {% if sort_by == 'most_likes' %}selected{% endif %}>最多点赞</option>
                        <option value="most_views" {% if sort_by == 'most_views' %}selected{% endif %}>最多浏览</option>
                    </select>
                </form>
            </div>
        </div>
    </div>
    
    <!-- 博客列表 -->
    <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-5">
        {% for blog in blogs %}
            <div class="col">
                <div class="card h-100">
                    <!-- 博客标签 -->
{#                    <div class="position-absolute top-3 right-3 z-10">#}
{#                        <span class="badge bg-gradient-to-r from-purple-600 to-pink-500 text-white">#}
{#                            {{ blog.category.name|default:"未分类" }}#}
{#                        </span>#}
{#                    </div>#}
                    
                    <!-- 博客头部 -->
                    <div class="card-header">
                        <a href="{% url 'blog:blog_detail' blog.id %}" class="text-white hover:text-pink-200">
                            {{ blog.title }}
                        </a>
                    </div>
                    
                    <!-- 博客内容预览 -->
                    <div class="card-body">
                        <p class="card-text text-muted">
                            {{ blog.content|default:''|striptags|truncatechars:120 }}
                        </p>
                    </div>
                    
                    <!-- 博客底部信息 -->
                    <div class="card-footer text-body-secondary">
                        <div class="d-flex justify-content-between items-center">
                            <div class="d-flex align-items-center">
                                {% if blog.author.userprofile.avatar %}
                                    <a href="{% url 'author:user_page' blog.author.id %}">
                                        <img src="{{ blog.author.userprofile.avatar.url }}" alt="" width="32" height="32" class="d-inline-block align-text-top rounded-circle">
                                    </a>
                                {% else %}
                                    <!-- 可以使用一个默认头像图片或者简单的占位符 -->
                                    <img src="{% static 'img/headicon/default.png' %}" alt="默认头像" width="32" height="32" class="d-inline-block align-text-top rounded-circle">
                                {% endif %}
                                <span class="ms-2 text-secondary">{{ blog.author.username }}</span>
                            </div>
                            <div class="text-sm">
                                {{ blog.create_time|date:'Y-m-d' }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% empty %}
            <!-- 无博客时的提示 -->
            <div class="col-12 text-center py-10">
                <div class="mb-4">
                    <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#ccc" class="bi bi-file-text" viewBox="0 0 16 16">
                        <path d="M5 4a.5.5 0 0 0 0 1h6a.5.5 0 0 0 0-1H5zm-.5 2.5A.5.5 0 0 1 5 6h6a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zM5 8a.5.5 0 0 0 0 1h6a.5.5 0 0 0 0-1H5zm0 2a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1H5z"/>
                        <path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2zm10-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1z"/>
                    </svg>
                </div>
                <h3 class="text-muted mb-2">暂无博客</h3>
                <p class="text-sm text-gray-500">还没有人发布博客，成为第一个发布者吧！</p>
                <a href="{% url 'blog:pub_blog' %}" class="btn btn-warning mt-3">
                    立即发布
                </a>
            </div>
        {% endfor %}
    </div>
    
    <!-- 加载更多按钮 -->
    {% if blogs|length > 0 %}
        <div class="text-center mt-30">
            <button class="btn btn-outline-primary px-6 py-2 rounded-full hover:bg-primary hover:text-white transition-all duration-300">
                加载更多
            </button>
        </div>
    {% endif %}
{% endblock %}